package com.dk.controller;

import com.alibaba.fastjson.JSONObject;
import com.dk.pojo.Item;
import com.dk.pojo.Type;
import com.dk.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("userController")
public class UserController {

    @RequestMapping("test")
    public String test(Model model){
 /*       model.addAttribute("u","张三");

        List<User> users = new ArrayList<>();
        users.add(new User(1,"张三","男"));
        users.add(new User(2,"李四","女"));
        users.add(new User(3,"王二","男"));
        model.addAttribute("userList",users);*/

        List<Item> items = new ArrayList<>();
        items.add(new Item(1,"旺旺",1,1));
        items.add(new Item(2,"辣条",0,1));
        items.add(new Item(3,"香烟",1,2));
        items.add(new Item(4,"烟花",0,3));
        model.addAttribute("it",items);

        List<Type> types = new ArrayList<>();
        types.add(new Type(1,"饮食"));
        types.add(new Type(2,"生活用品"));
        types.add(new Type(3,"烟火"));
        model.addAttribute("type",types);
        return "list";
    }

    @RequestMapping("updateInfo")
    public String updateInfo(Model model){
        Item item = new Item(4,"菜刀",0,1);
        model.addAttribute("items",item);
        List<Type> types = new ArrayList<>();
        types.add(new Type(1,"电器"));
        types.add(new Type(2,"文具"));
        types.add(new Type(3,"用品"));
        model.addAttribute("type",types);
        return "update";
    }

    @RequestMapping("toUpdate")
    @ResponseBody
    public String toUpdate( Item item){
        System.out.println(JSONObject.toJSON(item));
        return "修改成功";
    }
}
